package com.yueman.ptoolopenticket.ticket.utils.lixin;

import lombok.SneakyThrows;

import java.io.IOException;
import java.io.InputStream;
import java.util.Base64;

public class BaseImg {
    /**
     * 将图片转为Base64
     *
     * @param
     * @return
     */
    @SneakyThrows
    public static String Base64Img(InputStream fileInputStream) {
        String base64Str = "";
        try {
            Base64.Encoder encoder = Base64.getEncoder();
            //获取流的大小
            int available = fileInputStream.available();
            byte[] bytes = new byte[available];
            fileInputStream.read(bytes);
            fileInputStream.close();
            base64Str = encoder.encodeToString(bytes);
            return base64Str;
        } catch (IOException e) {
            e.printStackTrace();
        }
        return base64Str;
    }
}
